package application

import (
	"demo/flutter_server/application/models"
	"demo/flutter_server/domain/catalog"

	"github.com/gofiber/fiber/v2"
)

type CatalogController struct {
	catalogService *catalog.CatalogService
}

func NewCatalogController(
	catalogService *catalog.CatalogService,
) *CatalogController {
	return &CatalogController{
		catalogService,
	}
}

func (t *CatalogController) GetCatalog(c *fiber.Ctx) error {
	page := c.QueryInt("page", 1)
	pageSize := 15

	if datas, err := t.catalogService.GetCatalog(page, pageSize); err != nil {
		return c.JSON(models.Response{
			Code: models.ResponseServerError,
		})
	} else {
		return c.JSON(models.Response{
			Code: models.ResponseSuccess,
			Data: datas,
		})
	}
}
